function Distance(x1,y1,x2,y2){
	var x = (x2 - x1)*(x2 - x1);
	var y = (y2 - y1)*(y2 - y1);
	return Math.sqrt(x + y);
}

function Triangle(a, b, c){
	this.a = a;
	this.b = b;
	this.c = c;
}

Triangle.prototype.perimeter = function(){
	return this.a + this.b + this.c;
}

function Square(a, b){
	this.a = a;
	this.b = b;	
}

Square.prototype.perimeter = function(){
	return 2*this.a + 2*this.b;
}

function Vertex(x,y){
	this.x = x;
	this.y = y;
}

function stringToVertexes(str){
	var result = [];
	var textArr = str.split(',');
	
	for(var i = 0; i + 1 < textArr.length; i = i + 2){
		var x = parseInt(textArr[i],10);
		var y = parseInt(textArr[i+1],10);
		result.push(new Vertex(x, y));
	}
	
	return result;
}

function onClick(){
	var element = document.getElementById('num');
	if(!element || !element.value){
		return;
	}
	var text = element.value;
	// esli dannue ravno 3 
	// poshitat' treugol'nik
	// inache esli dannue ravno 4
	// poshitat' kvadrat
	
	// + poluchit stroku vvoda
	// + razdelit ta chasti
	// + perevesto chasti v chisla
	// + poschitat distanciyu
	// - prisvoit a, b, c
	var vertexes = stringToVertexes(text);
	if(vertexes.length === 3){
		var a = Distance(
			vertexes[0].x, 
			vertexes[0].y, 
			vertexes[1].x, 
			vertexes[1].y);
		var b = Distance(
			vertexes[1].x, 
			vertexes[1].y, 
			vertexes[2].x, 
			vertexes[2].y);
		var c = Distance(
			vertexes[2].x, 
			vertexes[2].y, 
			vertexes[0].x, 
			vertexes[0].y);

		console.log('a: ' + a);
		console.log('b: ' + b);
		console.log('c: ' + c);
		var t = new Triangle(a, b, c);
		
		document.getElementById('trianglePerimeter').innerText = t.perimeter();

		var s = new Square(a, b);
		
		document.getElementById('squarePerimeter').innerText = s.perimeter();
		return;
	}	
}